set doc off
set verify off
set serveroutput on size 1000000;

declare   
    l_total_extracted_rates	NUMBER;
	l_total_imported_rates	NUMBER;
	l_total_extracted_range	NUMBER;
	l_total_imported_range	NUMBER;
	l_func_id				VARCHAR2(100):='CAPGLREC_RATE_HIST';	 
                             
begin

    SELECT COUNT(1) 
	INTO l_total_extracted_rates
    from gl_historical_rates 
    where set_of_books_id = (select set_of_books_id 
                             from gl_sets_of_books 
                             where upper(short_name) = upper('&1'));
  
    SELECT COUNT(1) 
	INTO l_total_extracted_range
    from gl_historical_rate_ranges 
    where set_of_books_id = (select set_of_books_id 
                             from gl_sets_of_books 
                             where upper(short_name) = upper('&1'));

	SELECT COUNT(1) 
	INTO l_total_imported_rates
	FROM CRST_GL_HISTORICAL_RATES;
	
	SELECT COUNT(1) 
	INTO l_total_imported_range
	FROM CRST_GL_HIST_RATE_RANGES ;
	
	dbms_output.put_line('Function: '||l_func_id);		
	dbms_output.put_line('Total Extracted (Rates): '||TO_CHAR(l_total_extracted_rates)) ;
	dbms_output.put_line('Total Imported (Rates):  '||TO_CHAR(l_total_imported_rates));
	IF l_total_extracted_rates <> l_total_imported_rates THEN
		dbms_output.put_line('Error: No. of Records do not match!');
	END IF;		
	
	dbms_output.put_line('Total Extracted (Ranges): '||TO_CHAR(l_total_extracted_range)) ;
	dbms_output.put_line('Total Imported (Ranges):  '||TO_CHAR(l_total_imported_range));
	IF l_total_extracted_range <> l_total_imported_range THEN
		dbms_output.put_line('Error: No. of Records do not match!');
	END IF;		
						
EXCEPTION
	WHEN OTHERS THEN	
		dbms_output.put_line('Function Error: '||l_func_id);
	

end;
/


